import libtcodpy as T

from settings import *
from util import *
from random import choice
# from mob import Monster
import mob

import ui

class Corpse(object):
    """Represents all manner of dead creatures"""
    # The following would be used for Madness' class-based random select
    # ALL = []
    # __metaclass__ = Register
    # ABSTRACT = True
    # common = 10

    # age = 0
    turn_created = 0
    glyph = '%', T.dark_grey
    plural = False
    name = 'unidentifiable corpse'

    @property
    def descr(self):
        return self.name

    @property
    def age(self):
        return ui.GAME.turns - self.turn_created

    @property
    def a(self):
        if self.plural:
            return self.descr
        else:
            d = self.descr
            if d[0].lower() in 'aeiuo':
                return 'an ' + self.descr
            else:
                return 'a ' + self.descr

    def __init__(self, src_mon = None, age = None):
        """Creates a new corpse, randomly or based on attributes"""
        cps_names = ('dead %s',\
                'cadaverous %s',\
                'perished %s',\
                'deceased %s',\
                'lifeless %s',\
                'wasted %s',\
                '%s corpse',\
                '%s cadaver',\
                '%s body')
        if src_mon:
            self.name = choice(cps_names) % src_mon.name
            try:
                self.glyph = '%', src_mon.glyph[1]
            except TypeError:
                # We get TypeErrors when we try to subscript rainbow glyphs
                pass    # We just leave the glyph the default color
        if age:
            # Age the corpse appropriately
            self.turn_created = ui.GAME.turns - age
        else:
            # If not defined, we make a fresh corpse
            self.turn_created = ui.GAME.turns

    def describe_corpse(self, player):
        adj = []

        if self.age < 10:
            adj.append(choice(('very fresh','bloody','twitching')))
        elif self.age < 50:
            adj.append(choice(('fresh','warm','trickling','weeping')))
        elif self.age < 100:
            adj.append(choice(('stiff','cold','oozing','slimy')))
        elif self.age < 200:
            adj.append(choice(('decaying','putrid','rotting','moldy',\
                    'foul','fetid','noisome')))
        elif self.age >= 200:
            adj.append(choice(('rotten','worm-eaten','corrupt','rancid')))

        if 'h' in player.effects:
            adj.append(choice(('captivating','delicious','adorable',\
                    'tempting','bewitching','enchanting')))
        if 'f' in player.effects:
            adj.append(choice(('terrifying','awful','ghastly','hideous',\
                    'striking','imposing')))

        return ', '.join(adj) + ' ' + self.descr

